home *** CD-ROM | disk | FTP | other *** search
/ Micromanía: 150 Juegos 2010 / 150Juegos_16.iso / Shareware / Juegos Flash / jack_vs_kelly.dcr / 00021_sprite.flash.opponent.ai.attack.class.ls < prev    next >
Encoding:
Text File  |  2003-05-02  |  9.1 KB  |  231 lines

  1. property ancestor, p_opponent_jump_threshold, p_horizontal_melee_threshold, p_horizontal_environment_threshold, p_health_threshold, p_last_loc
  2.  
  3. on new me, parent, sprite_ref, sprite_type, player_num
  4.   ancestor = script("sprite.flash.opponent.ai.class").new(parent, sprite_ref, sprite_type, player_num)
  5.   me.p_opponent_jump_threshold = 50
  6.   me.p_horizontal_melee_threshold = 70
  7.   me.p_horizontal_environment_threshold = 50
  8.   me.p_health_threshold = 0.25
  9.   return me
  10. end
  11.  
  12. on determine_action me, inputs
  13.   action = #stand
  14.   if inputs.state = #dead then
  15.     return #win
  16.   else
  17.     if me.p_injured then
  18.       if inputs.ldx < (me.p_horizontal_environment_threshold * 2) then
  19.         return [#jump_right, #jump][random(2)]
  20.       else
  21.         if inputs.rdx < (me.p_horizontal_environment_threshold * 2) then
  22.           return [#jump_left, #jump][random(2)]
  23.         else
  24.           if inputs.dx > 0 then
  25.             return [#jump_right, #jump, #jump_left, #walk_right][random(4)]
  26.           else
  27.             if inputs.dx < 0 then
  28.               return [#jump_left, #jump, #jump_right, #walk_left][random(4)]
  29.             end if
  30.           end if
  31.         end if
  32.       end if
  33.     else
  34.       if inputs.attacking then
  35.         if inputs.state = #special then
  36.           if inputs.dx > 0 then
  37.             action = me.fuzzy_move([#jump_left, #jump_left, #jump_left, #jump_right, #jump_right, #block])
  38.           else
  39.             if inputs.dx <= 0 then
  40.               action = me.fuzzy_move([#jump_right, #jump_right, #jump_right, #jump_left, #jump_left, #block])
  41.             end if
  42.           end if
  43.           return action
  44.         else
  45.           if (inputs.dx < (me.p_horizontal_melee_threshold * 1.5)) and (inputs.dx > (-me.p_horizontal_melee_threshold * 1.5)) then
  46.             if inputs.dy > me.p_opponent_jump_threshold then
  47.               if inputs.dy > 0 then
  48.                 action = [#high_punch, #high_kick][random(2)]
  49.               else
  50.                 if inputs.dy > -me.p_opponent_jump_threshold then
  51.                   action = #mid_kick
  52.                 end if
  53.               end if
  54.             else
  55.               if random(5) = 5 then
  56.                 action = me.attack(action)
  57.               else
  58.                 if random(10) = 10 then
  59.                   action = #crouch
  60.                 else
  61.                   action = #block
  62.                 end if
  63.               end if
  64.             end if
  65.             return action
  66.           end if
  67.         end if
  68.       end if
  69.     end if
  70.   end if
  71.   if me.p_last_loc = me.p_loc then
  72.     if inputs.ldx < (me.p_horizontal_environment_threshold * 1.5) then
  73.       action = me.fuzzy_move([#walk_right, #jump_right])
  74.     else
  75.       if inputs.rdx < (me.p_horizontal_environment_threshold * 1.5) then
  76.         action = me.fuzzy_move([#walk_left, #jump_left])
  77.       else
  78.         if (inputs.dx > -me.p_horizontal_melee_threshold) and (inputs.dx < me.p_horizontal_melee_threshold) then
  79.           action = me.attack(action, inputs)
  80.         else
  81.           action = me.fuzzy_move([#walk_left, #walk_right, #walk_left, #walk_right, #crouch, #block, #stand, #jump_right, #jump_left])
  82.         end if
  83.       end if
  84.     end if
  85.   else
  86.     health_status = (me.p_health > me.p_health_threshold) or (inputs.health < me.p_health_threshold)
  87.     health_status = health_status = (random(100) < 80)
  88.     if health_status then
  89.       case me.p_state of
  90.         #walk_left, #walk_right, #stand, #crouch, #block:
  91.           if inputs.ldx < me.p_horizontal_environment_threshold then
  92.             action = me.fuzzy_move([#walk_right, #jump_right])
  93.           else
  94.             if inputs.rdx < me.p_horizontal_environment_threshold then
  95.               action = me.fuzzy_move([#walk_left, #jump_left])
  96.             else
  97.               if inputs.dx > me.p_horizontal_melee_threshold then
  98.                 if inputs.op_loc[2] < 0 then
  99.                   action = me.fuzzy_move([#jump_left, #walk_left, #jump_left, #walk_left, #jump_left, #walk_left, #jump_left, #walk_left, #jump_left, #walk_left, #jump_left, #walk_left, #jump_left, #walk_left, #special])
  100.                 else
  101.                   action = me.fuzzy_move([#walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #special])
  102.                 end if
  103.               else
  104.                 if inputs.dx < -me.p_horizontal_melee_threshold then
  105.                   if inputs.op_loc[2] < 0 then
  106.                     action = me.fuzzy_move([#jump_right, #walk_right, #jump_right, #walk_right, #jump_right, #walk_right, #jump_right, #walk_right, #jump_right, #walk_right, #jump_right, #walk_right, #jump_right, #walk_right, #special])
  107.                   else
  108.                     action = me.fuzzy_move([#walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #special])
  109.                   end if
  110.                 else
  111.                   if inputs.op_loc[2] < 0 then
  112.                     if inputs.op_loc[2] > -me.p_opponent_jump_threshold then
  113.                       action = me.attack(action, inputs)
  114.                     else
  115.                       action = me.fuzzy_move([#jump, #stand])
  116.                     end if
  117.                   else
  118.                     action = me.attack(action, inputs)
  119.                   end if
  120.                 end if
  121.               end if
  122.             end if
  123.           end if
  124.         #jump, #jump_left, #jump_right:
  125.           action = me.jump_attack(inputs, action)
  126.       end case
  127.     else
  128.       case me.p_state of
  129.         #walk_left, #walk_right, #stand, #crouch, #block:
  130.           if inputs.ldx < (me.p_horizontal_environment_threshold * 1.5) then
  131.             action = me.fuzzy_move([#walk_right, #jump_right])
  132.           else
  133.             if inputs.rdx < (me.p_horizontal_environment_threshold * 1.5) then
  134.               action = me.fuzzy_move([#walk_left, #jump_left])
  135.             else
  136.               if inputs.rdx < me.p_horizontal_environment_threshold then
  137.                 if inputs.dx > -me.p_horizontal_melee_threshold then
  138.                   action = me.fuzzy_move([#jump_left, #walk_left])
  139.                 else
  140.                   action = me.fuzzy_move([#walk_left])
  141.                 end if
  142.               else
  143.                 if inputs.dx > -me.p_horizontal_melee_threshold then
  144.                   if inputs.op_loc[2] < -me.p_opponent_jump_threshold then
  145.                     action = me.fuzzy_move([#jump_right, #walk_right, #jump_right, #walk_right, #jump_right, #walk_right, #jump_right, #walk_right, #jump_right, #walk_right, #jump_right, #walk_right, #jump_right, #walk_right, #special])
  146.                   else
  147.                     action = me.fuzzy_move([#walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #walk_right, #special])
  148.                   end if
  149.                 else
  150.                   if inputs.dx < me.p_horizontal_melee_threshold then
  151.                     if inputs.op_loc[2] < -me.p_opponent_jump_threshold then
  152.                       action = me.fuzzy_move([#jump_left, #walk_left, #jump_left, #walk_left, #jump_left, #walk_left, #jump_left, #walk_left, #jump_left, #walk_left, #jump_left, #walk_left, #jump_left, #walk_left, #special])
  153.                     else
  154.                       action = me.fuzzy_move([#walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #walk_left, #special])
  155.                     end if
  156.                   end if
  157.                 end if
  158.               end if
  159.             end if
  160.           end if
  161.         #jump, #jump_left, #jump_right:
  162.           action = me.jump_defend(inputs, action)
  163.       end case
  164.     end if
  165.   end if
  166.   me.p_last_loc = me.p_loc
  167.   return action
  168. end
  169.  
  170. on jump_attack me, inputs, action
  171.   if (inputs.dx > -me.p_horizontal_melee_threshold) and (inputs.dx < me.p_horizontal_melee_threshold) then
  172.     action = me.fuzzy_move([#mid_kick, #mid_kick, #mid_kick, #mid_kick, #high_punch, #high_kick])
  173.   end if
  174.   return action
  175. end
  176.  
  177. on jump_defend me, inputs, action
  178.   if (inputs.dx > -me.p_horizontal_melee_threshold) and (inputs.dx < me.p_horizontal_melee_threshold) then
  179.     action = me.fuzzy_move([#block, #block, #block, #block, #block, #mid_kick, #high_punch, #high_kick])
  180.   end if
  181.   return action
  182. end
  183.  
  184. on attack me, action
  185.   if random(10) = 1 then
  186.     action = #fast_kick
  187.   else
  188.     action = [#high_punch, #high_kick, #mid_kick][random(3)]
  189.   end if
  190.   return action
  191. end
  192.  
  193. on fuzzy_move me, actions
  194.   change_action = 0
  195.   if random(50) = 50 then
  196.     change_action = 1
  197.   end if
  198.   action = actions[random(actions.count)]
  199.   case action of
  200.     #walk_left:
  201.       if change_action then
  202.         action = #jump_left
  203.       end if
  204.     #walk_right:
  205.       if change_action then
  206.         action = #jump_right
  207.       end if
  208.     #jump_left:
  209.       if change_action then
  210.         action = #walk_left
  211.       end if
  212.     #jump_right:
  213.       if change_action then
  214.         action = #walk_right
  215.       end if
  216.     #jump:
  217.       if change_action then
  218.         action = #stand
  219.       end if
  220.     #stand:
  221.       if change_action then
  222.         action = #jump
  223.       end if
  224.   end case
  225.   return action
  226. end
  227.  
  228. on dispose me
  229.   callAncestor(#dispose, [me])
  230. end
  231.